package cn.edu.huanu.controller;

import cn.edu.huanu.pojo.Cart;
import cn.edu.huanu.pojo.User;
import cn.edu.huanu.service.OrderServcie;
import cn.edu.huanu.service.impl.OrderServiceImpl;
import cn.edu.huanu.utils.JsonUtils;
import cn.edu.huanu.utils.R;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author hb
 * @date 2025-11-20 13:04:53
 */
@WebServlet("*.order")
public class OrderManagerAction extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        String servletPath = req.getServletPath();
        PrintWriter out = resp.getWriter();

        OrderServcie orderServcie=new OrderServiceImpl();

        HttpSession session = req.getSession();

        User u= (User)session.getAttribute("user");
        Cart cart =(Cart) session.getAttribute("cart");

        if("/load.order".equals(servletPath)){
            R r=orderServcie.loadOrderDatas(u.getId(),cart);
            out.println(JsonUtils.objectToJson(r));
        }
    }
}
